package mysql;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;



import dao.hive.Connect;

public class MysqlUtil {

	/**
	 * @param args
	 * @throws SQLException 
	 */
	public static String getRunningSql(String tablename ,String sql_ref) throws SQLException
	{
		Connection conn = Connect.GetMysqllocal();
		String runsql="";
		String getsql ="select sqlstmt from code_code where tablename='"+tablename+"" +
				"' and  sql_ref='"+sql_ref+"'";
		Statement sta = conn.createStatement();
		ResultSet rs = sta.executeQuery(getsql);
		if(rs.next())
		{
			runsql = rs.getString(1);
		}
		return runsql;
	}

	public static void insertToMysql(String tomysql,ResultSet rs) {
		// TODO Auto-generated method stub
		try {
			Connection conn = Connect.GetMysqlConn();
			PreparedStatement pra=conn.prepareStatement(tomysql);
			
			while(rs.next())
			{
			//	System.out.println(rs.getString(1)+"     "+rs.getInt(2));
				pra.setString(1, rs.getString(1));
				pra.setInt(2, rs.getInt(2));
				pra.addBatch();
			}
			pra.executeBatch();
			
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}
}
